#include "StdAfx.h"
#include "TestInfoManager.h"
#include <Markup/Markup.h>
#include "TestInfo.h"
#include "GroupInfo.h"
#include "../TestNumber/TestNumber.h"

TestInfoManager::TestInfoManager(void)
{
	CurrentTestId = 0;
	
	TestInfo* pTestInfo = NULL;
	GroupInfo* pGroupInfo = NULL;

	//============================================================
	// DEFAULT GEPT SETTINGS
	pTestInfo = new TestInfo;
	pTestInfo->TestId = 0;
	pTestInfo->Description = _T("GEPT");
	pTestInfo->CLF = _T("C:\\Program Files\\Sanako\\Lab\\Lab100\\Seating Plans\\GEPT.CLF");
	pTestInfo->BackGroundColor = RGB(215,227,238);
	pTestInfo->AdditionalStudentBackGroundColor = RGB(100,100,100);
	pTestInfo->AudioSource = _T("C:\\");
	
	pGroupInfo = new GroupInfo;
	pGroupInfo->Description = _T("GEPT01");
	pGroupInfo->InitTestNumber = TestNumber::Create(0,_T("123-1234-01001"));
	pGroupInfo->AudioDestination = _T("C:\\");
	pGroupInfo->TextColor = RGB(0,0,100);
	pGroupInfo->Language = _T("");

	pTestInfo->vGroupInfo.push_back(pGroupInfo);

	vTestInfo.push_back(pTestInfo);

	//============================================================
	// DEFAULT Hakka SETTINGS
	pTestInfo = new TestInfo;
	pTestInfo->TestId = 1;
	pTestInfo->Description = _T("Hakka");
	pTestInfo->CLF = _T("C:\\Program Files\\Sanako\\Lab\\Lab100\\Seating Plans\\Hakka.CLF");
	pTestInfo->BackGroundColor = RGB(215,227,238);
	pTestInfo->AdditionalStudentBackGroundColor = RGB(100,100,100);
	pTestInfo->AudioSource = _T("C:\\");

	pGroupInfo = new GroupInfo;
	pGroupInfo->Description = _T("Hakka01");
	pGroupInfo->InitTestNumber = TestNumber::Create(1,_T("AAA-AAAA-01001"));
	pGroupInfo->AudioDestination = _T("C:\\");
	pGroupInfo->TextColor = RGB(0,0,100);
	pGroupInfo->Language = _T("");

	pTestInfo->vGroupInfo.push_back(pGroupInfo);

	vTestInfo.push_back(pTestInfo);

	//============================================================
	// DEFAULT FLPT SETTINGS
	pTestInfo = new TestInfo;
	pTestInfo->TestId = 2;
	pTestInfo->Description = _T("FLPT");
	pTestInfo->CLF = _T("C:\\Program Files\\Sanako\\Lab\\Lab100\\Seating Plans\\FLPT.CLF");

	pTestInfo->BackGroundColor = RGB(215,227,238);
	pTestInfo->AdditionalStudentBackGroundColor = RGB(100,100,100);
	pTestInfo->AudioSource = _T("C:\\");

	pGroupInfo = new GroupInfo;
	pGroupInfo->Description = _T("FLTP01");
	pGroupInfo->InitTestNumber = TestNumber::Create(2,_T("AA001"));
	pGroupInfo->AudioDestination = _T("");
	pGroupInfo->TextColor = RGB(0,0,100);
	pGroupInfo->Language = _T("");
	pTestInfo->vGroupInfo.push_back(pGroupInfo);

	pGroupInfo = new GroupInfo;
	pGroupInfo->Description = _T("FLTP02");
	pGroupInfo->InitTestNumber = TestNumber::Create(2,_T("AA101"));
	pGroupInfo->AudioDestination = _T("");
	pGroupInfo->TextColor = RGB(232,100,0);
	pGroupInfo->Language = _T("");
	pTestInfo->vGroupInfo.push_back(pGroupInfo);

	pGroupInfo = new GroupInfo;
	pGroupInfo->Description = _T("FLTP03");
	pGroupInfo->InitTestNumber = TestNumber::Create(2,_T("AA201"));
	pGroupInfo->AudioDestination = _T("");
	pGroupInfo->TextColor = RGB(100,0,100);
	pGroupInfo->Language = _T("");
	pTestInfo->vGroupInfo.push_back(pGroupInfo);

	vTestInfo.push_back(pTestInfo);
}

TestInfoManager::~TestInfoManager(void)
{
	Clear();
}

BOOL TestInfoManager::Load( CMarkup& xml )
{
	if(xml.FindElem(_T("TestInfoManager")))
	{
		Clear();

		CurrentTestId = _ttoi(xml.GetAttrib(_T("CurrentTestId")));

		xml.IntoElem();

		while(xml.FindElem(_T("TestInfo")))
		{
			TestInfo* pTestInfo = new TestInfo(xml);
			vTestInfo.push_back(pTestInfo);
		}

		xml.OutOfElem();
		return true;
	}
	return false;
}

UINT TestInfoManager::GetCurrentTestId()
{
	return CurrentTestId;
}

BOOL TestInfoManager::SetCurrentTestId( UINT TestId )
{
	CurrentTestId = TestId;
	return true;
}

CString TestInfoManager::GetTestDescription()
{
	return vTestInfo[CurrentTestId]->GetDescription();
}

UINT TestInfoManager::GetTestSize()
{
	return vTestInfo.size();
}

CString TestInfoManager::GetTestDescription( UINT TestId )
{
	if( 0 <= TestId && TestId < GetTestSize()) 
		return vTestInfo[TestId]->GetDescription();
	else
	{
		//ASSERT(FALSE);
		return CString(_T("Undefined TestId"));
	}
}

void TestInfoManager::Clear()
{
	size_t size = vTestInfo.size();
	for(size_t i=0; i<size; ++i)
		SAFE_DELETE(vTestInfo[i]);
	vTestInfo.clear();
}

BOOL TestInfoManager::Save( CMarkup& xml )
{
	xml.AddElem(_T("TestInfoManager"));
	xml.AddAttrib(_T("CurrentTestId"),CurrentTestId);

	xml.IntoElem();

	size_t size = vTestInfo.size();
	for(size_t i=0; i<size; ++i)
		vTestInfo[i]->Save(xml);

	xml.OutOfElem();

	return true;
}

const CString& TestInfoManager::GetCLF()
{
	return vTestInfo[CurrentTestId]->GetCLF();
}

COLORREF TestInfoManager::GetBackGroundColor()
{
	return vTestInfo[CurrentTestId]->GetBackGroundColor();
}

COLORREF TestInfoManager::GetAdditionalStudentBackGroundColor()
{
	return vTestInfo[CurrentTestId]->GetAdditionalStudentBackGroundColor();
}

const CString& TestInfoManager::GetAudioSource()
{
	return vTestInfo[CurrentTestId]->GetAudioSource();
}

BOOL TestInfoManager::SetCLF( const CString& clf )
{
	return vTestInfo[CurrentTestId]->SetCLF(clf);
}

BOOL TestInfoManager::SetAudioSource( const CString& audioSource )
{
	return vTestInfo[CurrentTestId]->SetAudioSource(audioSource);
}

GroupInfo* TestInfoManager::GetGroupInfo( UINT i )
{
	return vTestInfo[CurrentTestId]->GetGroupInfo(i);
}

size_t TestInfoManager::GetGroupSize()
{
	return vTestInfo[CurrentTestId]->GetGroupSize();
}

GroupInfo* TestInfoManager::GetCurrentGroupInfo()
{
	return vTestInfo[CurrentTestId]->GetCurrentGroupInfo();
}

BOOL TestInfoManager::SetCurrentGroup( UINT i )
{
	return vTestInfo[CurrentTestId]->SetCurrentGroup(i);
}

UINT TestInfoManager::GetCurrentGroup()
{
	return vTestInfo[CurrentTestId]->GetCurrentGroup();
}
